// pages/load/load.js
let get = require("../../utils/util")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isRegister:true
  },
  onLoad(option){
    wx.login({
      success:res=>{
        get("user/login",{code:res.code}).then(res=>{
          wx.setStorageSync('token', res.data.token)
          if(res.data.if_new){
            this.setData({
              isRegister:false
            })
            console.log(this.data.isRegister);
          }else{
            wx.switchTab({
              url: '/pages/home/home',
            })
          
          }
        })
      }
    })
  },

  login(){
    wx.getUserProfile({
      desc:"获取用户信息",
      success:res=>{
        let info=res.userInfo
        get("user/info",{token:wx.getStorageSync('token'),userimg:info.avatarUrl,username:info.nickName},'POST').then(res=>{
          wx.switchTab({
            url: '/pages/home/home',
          })
        })

      },
      fail:res=>{
        wx.showToast({
          title: '请先登陆',
          icon:'none'
        })
      }
    })
  }
})